package org.example.classtopia.Repository;

import org.example.classtopia.Model.Entity.Curriculum;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface CurriculumRepository extends JpaRepository<Curriculum, Long> {
    
    /**
     * 根据用户ID查找课程
     */
    List<Curriculum> findByUserId(Long userId);
    
    /**
     * 根据用户ID和星期几查找课程
     */
    List<Curriculum> findByUserIdAndDay(Long userId, Integer day);
    
    /**
     * 删除用户的所有课程（重新同步时清空旧数据）
     */
    @Modifying
    @Transactional
    @Query("DELETE FROM Curriculum c WHERE c.userId = :userId")
    void deleteByUserId(Long userId);
}
